Library

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(leaflet)

Leaflet Test

Data

Sourced from: http://eric.clst.org/wupl/Stuff/gz_2010_us_050_00_5m.json http://eric.clst.org/wupl/Stuff/gz_2010_us_040_00_5m.json Need to cite US Census Beauro, see (http://eric.clst.org/Stuff/USGeoJSON) for more info All actual data sourced from NIOSH, need to find urls, etc. (add in dates / redownload for final)

uscounties <- rgdal::readOGR("data/counties_5m.json", "OGRGeoJSON")
## OGR data source with driver: GeoJSON 
## Source: "data/counties_5m.json", layer: "OGRGeoJSON"
## with 3221 features
## It has 6 fields
usstates   <- rgdal::readOGR("data/state_5m.json", "OGRGeoJSON")
## OGR data source with driver: GeoJSON 
## Source: "data/state_5m.json", layer: "OGRGeoJSON"
## with 52 features
## It has 5 fields

Test leaflet map with counties included ##Leaflet Test

leaflet(uscounties) %>%
  addTiles() %>%
  addPolygons(data = uscounties, color = "blue", weight = 1, fillOpacity = 0) %>%
  addPolygons(data = usstates, color = "black", weight = 5, fillOpacity = 0)

Data merging: rapidProgression

We will use rapidProgression_clean for these plots (only df that has county info built in) ##Data

rapidProg_raw <- read.csv("~/CWP-trends/data/rapidProgression_clean.csv")

rapidProg_raw$X <- NULL

Join State and Country DFs

uscounties$REGION <- NA
usstates$REGION   <- NA

states <- as.data.frame(usstates$NAME)
states$STATE <- (usstates$STATE)

df_counties <- as.data.frame(uscounties)
df_join     <- dplyr::left_join(df_counties, states, by = "STATE")
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y):
## '.Random.seed' is not an integer vector but of type 'NULL', so ignored

Assign Rergions to states/counties

Northern Appalachia

df_join <- within(df_join, REGION[`usstates$NAME` %in% c( 'Maryland'
                                                        , 'Pennsylvania'
                                                        , 'Ohio'
                                                        )
                                 ] <- 'Northern Appalachia')

df_join <- within(df_join, REGION[`usstates$NAME` == 'West Virginia' & NAME %in% c( "Barbour"
                                                                                  , "Brooke"
                                                                                  , "Clay"
                                                                                  , "Grant"
                                                                                  , "Greenbrier"
                                                                                  , "Harrison"
                                                                                  , "Lincoln"
                                                                                  , "Marion"
                                                                                  , "Marshall"
                                                                                  , "Monongalia"
                                                                                  , "Preston"
                                                                                  , "Raleigh"
                                                                                  , "Randolph"
                                                                                  , "Tucker"
                                                                                  , "Upshur"
                                                                                  , "Webster"
                                                                                  )
                                  ] <- 'Northern Appalachia'
                  )

Mid-West

df_join <- within(df_join, REGION[`usstates$NAME` %in% c( 'Illinois'
                                                        , 'Indiana'
                                                        )
                                 ] <- 'Mid-West')

df_join <- within(df_join, REGION[`usstates$NAME` == 'Kentucky' & NAME %in% c( "Hopkins"
                                                                             , "Union"
                                                                             , "Webster"
                                                                             )
                                  ] <- 'Mid-West')

Central Appalachia

df_join <- within(df_join, REGION[`usstates$NAME` %in% c( 'Virginia'
                                                        , 'Tennessee'
                                                        )
                                 ] <- 'Central Appalachia')

df_join <- within(df_join, REGION[`usstates$NAME` == 'Kentucky' & NAME %in% c( "Bell"
                                                                             , "Boyd"
                                                                             , "Breathitt"
                                                                             , "Christian"
                                                                             , "Clay"
                                                                             , "Daviess"
                                                                             , "Estill"
                                                                             , "Floyd"
                                                                             , "Harlan"
                                                                             , "Henderson"
                                                                             , "Jackson"
                                                                             , "Johnson"
                                                                             , "Knott"
                                                                             , "Knox"
                                                                             , "Laurel"
                                                                             , "Lawrence"
                                                                             , "Leslie"
                                                                             , "Letcher"
                                                                             , "Martin"
                                                                             , "Mclean"
                                                                             , "Muhlenberg"
                                                                             , "Perry"
                                                                             , "Pike"
                                                                             , "Whitley"
                                                                             , "Wolfe"
                                                                             )
                                  ] <- 'Central Appalachia')

df_join <- within(df_join, REGION[`usstates$NAME` == 'West Virginia' & NAME %in% c( "Boone"
                                                                             , "Fayette"
                                                                             , "Kanawha"
                                                                             , "Logan"
                                                                             , "McDowell"
                                                                             , "Mingo"
                                                                             , "Nicholas"
                                                                             , "Wayne"
                                                                             , "Wyoming"
                                                                           
                                                                             )
                                  ] <- 'Central Appalachia')

Southern Appalachia

df_join <- within(df_join, REGION[`usstates$NAME` %in% c( 'Alabama'
                                                        , 'Arkansas'
                                                        , 'Louisiana'
                                                        )
                                  ] <- 'Southern Appalachia')

West

df_join <- within(df_join, REGION[`usstates$NAME` %in% c( 'Arizona'
                                                        , 'Colorado'
                                                        , 'Montana'
                                                        , 'New Mexico'
                                                        , 'North Dakota'
                                                        , 'Oklahoma'
                                                        , 'Texas'
                                                        , 'Utah'
                                                        , 'Wyoming'
                                                        , 'Washington'
                                                        )
                                  ] <- 'West')

Save df_join for loading into server.ui

save(df_join, file = "data/serverData.RData")